package com.spring.boot.handler;

import com.spring.boot.constants.CommonConstants;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author zhengzihong
 * @date 2018/2/24
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    private Map<String,Object> exceptionHandler(HttpServletRequest req,Exception e){
        Map<String,Object> map = new HashMap<String,Object>(10);
        map.put(CommonConstants.SUCCESS,false);
        map.put(CommonConstants.ERROR_MSG,e.getMessage());
        return map;
    }


}
